package com.kll.carolinehmibiz.presentation.presenter

import android.content.Context
import com.kll.carolinehmibiz.OperationManager
import com.kll.carolinehmibiz.model.OperateListener
import com.kll.carolinehmibiz.net.bean.UploadFileResponse
import com.kll.carolinehmibiz.presentation.BasePresenter
import com.kll.carolinehmibiz.presentation.listener.PersonalAvatarProtocol
import java.io.File

class PersonalAvatarPresenter(context: Context, mView: PersonalAvatarProtocol.IView): BasePresenter(context), PersonalAvatarProtocol.IPresenter {
    private val mView: PersonalAvatarProtocol.IView? = mView
    private var uploadHeadImgIsBusying = false

    override fun uploadHeadImg(file: File) {
        if (uploadHeadImgIsBusying) return
        uploadHeadImgIsBusying = true
        OperationManager.getInstancce().uploadHeadImg(file, object : OperateListener {
            override fun onSuccess(state: Int, obj: Any?) {
                uploadHeadImgIsBusying = false
                if (state == 200) {
                    mView?.uploadHeadImgSuccessed(obj as UploadFileResponse)
                }
            }

            override fun onFail(code: Int, message: String) {
                uploadHeadImgIsBusying = false
                mView?.uploadHeadImgFailed(code, message)
            }

        })
    }
}